<?php
/**
 * Joomla! 1.6 component WoWRoster
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
  
// Turn on debugging if needed
//ini_set('display_errors', 1);

// Include the syndicate functions only once

require (dirname(__FILE__).DS.'inc'.DS.'update.lib.php');
require (dirname(__FILE__).DS.'inc'.DS.'apiguildupdate.php');
include_once (dirname(__FILE__).DS.'roster_db.php');
include_once (dirname(__FILE__).DS.'page_display.php');
$document = & JFactory :: getDocument();
$document->addStyleSheet(getRosterPath("roster").'css/style.css');
$document->addStyleSheet(getRosterPath("roster").'css/demo_table.css');
// Plugins
$ginfo = getGuildInfo();
foreach ( $ginfo as $config )
{
}
list($region, $locale) = explode('-',$config->lang);
//echo $region.'<br>'.$locale.'<br>';
include_once (dirname(__FILE__).DS.'plugins/plugins.php');

	$db =& JFactory::getDBO();
	$query = "SELECT * FROM ".$db->nameQuote('#__guild_guilds')." WHERE `guild_name` = '$config->name' AND `server` = '$config->realm'";
	$db->setQuery($query);
	$row = $db->loadAssoc();
	//update time to time() unix value
	$updatetime = (($config->update_hours * 60) * 60);
	$currenttime = time();
	if (($row['update_time'] + $updatetime) < $currenttime)
	{
		jimport('armorysuite.smart.drops');
		$api = new WowAPI($config->region);
		// BUILD THE PAGE this is gona be huge
		//getView();

		$guild = $api->Guild->getGuildInfo($config->realm,$config->name,'members');
		$gupdate = new apiguildUpdate;
		$gupdate->update_guild($guild,$config->region);
	}
	else
	{
		echo 'no update needed<br>';
	}
echo 'I display the members list!';
$view = JRequest::getVar('view');
  
  switch($view) {
	case 'character':
			echo 'I display characters... not!';
      break;
	/*case 'character-gear':
      if (getPlugin('char_roster')) {
        if (enabledPluginCRoster())
          viewCharacterGear("");
	    else {
	      displayErrorMessage("Character Roster is currently disabled.");
		  $currentUrl = JURI::current();
          echo "<meta http-equiv='refresh' content='4;URL=".$currentUrl."'>";
		}
	  }
	  else {
	    displayErrorMessage("The Character Roster does not appear to be installed. <br />Please visit pixelbyte.dk for more information.");
		$currentUrl = JURI::current();
        echo "<meta http-equiv='refresh' content='6;URL=".$currentUrl."'>";
	  }
      break;*/
	case 'stats':	  viewStats();	   break;
	case 'admin':	  viewAdmin();	   break;
	case 'account':	  if ($enabled) {viewAccount();} else {viewRoster("");} break;
	case 'guild-roster':  displayRoster($row['guild_id']);  break;
    default:		  displayRoster($row['guild_id']);  break;
  }

/*
echo '<table><tr><td>name</td><td>class</td><td>race</td><td>gender</td><td>level</td><td>Apoints</td></tr>';
foreach ($guild['members'] as $id => $info)
{
echo '<tr><td>'.$info['character']['name'].'</td>';
echo '<td>'.$info['character']['class'].'</td>';
echo '<td>'.$info['character']['race'].'</td>';
echo '<td>'.$info['character']['gender'].'</td>';
echo '<td>'.$info['character']['level'].'</td>';
echo '<td>'.$info['character']['achievementPoints'].'</td></tr>';
}
echo '</table>';
echo '<pre>';
print_r($guild);
echo '<pre>';
*/


?>